package com.nc.user.service.impl;

import com.nc.user.dao.FrmUsersDao;
import com.nc.user.model.entity.FrmUsers;
import com.nc.user.service.UserService;
import com.nc.user.tool.tool.EDcrypionUtils;
import com.plug.result.ReqPage;
import com.plug.result.RetResponse;
import com.plug.result.RetResult;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 创建人:    xvzhe
 * 创建时间:
 * 修改时间:
 * 版本:      v1.0
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    FrmUsersDao frmUsersDao;

    @Override
    public RetResult updatePassword(String psd, String npsd) {
        FrmUsers fspuser = (FrmUsers) SecurityUtils.getSubject().getSession().getAttribute("Users");
        fspuser = frmUsersDao.findByMobile(fspuser.getMobile());
        if (fspuser.getPassword().equals(EDcrypionUtils.shiroPassword(psd))) {
            fspuser.setPassword(EDcrypionUtils.shiroPassword(npsd));
            frmUsersDao.save(fspuser);
            return RetResponse.makeOKRsp("修改成功");
        } else {
            return RetResponse.makeErrRsp("原密码不正确");
        }
    }
}
